<template>
  <div class="index-lists">
    <el-card class="!border-none mt-4" shadow="never">
      <div style="display: flex; justify-content: space-between">
        <div>
          <el-button v-perms="['basic:add']" type="primary" @click="handleAdd()">
            <template #icon>
              <icon name="el-icon-Plus"/>
            </template>
            新增
          </el-button>
        </div>
        <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
          <el-form-item label="合同名称" prop="contractName">
            <el-input class="w-[280px]" v-model="queryParams.contractName"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="resetPage">查询</el-button>
            <el-button @click="resetParams">重置</el-button>
          </el-form-item>
        </el-form>

      </div>
      <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
        <el-table-column label="ID" prop="id" min-width="50"/>
        <el-table-column type="selection" width="55"/>
        <el-table-column label="合同编号" prop="contractId" min-width="100"/>
        <el-table-column label="合同名称" prop="contractName" min-width="100"/>
        <el-table-column label="合同金额" prop="amount" min-width="100"/>
        <el-table-column label="合同开始时间" prop="contractStartTime" min-width="100"/>
        <el-table-column label="合同结束时间" prop="contractEndTime" min-width="100"/>
        <el-table-column label="合同类型" prop="contractType" min-width="100"/>
        <el-table-column label="客户签约人" min-width="100"/>
        <el-table-column label="我方签约人" min-width="100"/>
        <el-table-column label="跟进状态" prop="upstatus" min-width="100"/>
        <el-table-column label="下次跟进时间" prop="upstatustime" min-width="100"/>
     <el-table-column label="操作" width="120" fixed="right">
            <template #default="{ row }">
                <el-button
                    v-perms="['basic:edit']"
                    type="primary"
                    link
                    @click="handleEdit(row)"
                >
                    编辑
                </el-button>
                <el-button
                    v-perms="['basic:del']"
                    type="danger"
                    link
                    @click="handleDelete(row.id)"
                >
                    删除
                </el-button>
            </template>
        </el-table-column>
      </el-table>
      <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists"/>
      </div>
    </el-card>
   <edit-popup
        v-if="showEdit"
        ref="editRef"
        @success="getLists"
        @close="showEdit = false"
    />
  </div>
</template>
<script lang="ts" setup name="basic">
import {basicDelete, basicLists} from '@/api/basic'
import {usePaging} from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
  contractName: '',
  customerName: '',
  amount: '',
  gatheringAmount: '',
  contractStartTimeStart: '',
  contractStartTimeEnd: '',
  contractEndTimeStart: '',
  contractEndTimeEnd: '',
  dateContractSigning: '',
  isUncoil: '',
  correspondingCustomer: '',
  correspondingBusiness: '',
  contractValidTimeStart: '',
  contractValidTimeEnd: '',
  partySigner: '',
  partyPhone: '',
  contractType: '',
  partybFirm: '',
  partybSigner: '',
  partybPhone: '',
  signedDateStart: '',
  signedDateEnd: '',
  contractDateStart: '',
  contractDateEnd: '',
  remarks: '',
  contractState: '',
  collaborator: '',
  signedDate: ''
})

const {pager, getLists, resetPage, resetParams} = usePaging({
  fetchFun: basicLists,
  params: queryParams
})

// const handleAdd = async () => {
//     showEdit.value = true
//     await nextTick()
//     editRef.value?.open('add')
// }

// const handleEdit = async (data: any) => {
//     showEdit.value = true
//     await nextTick()
//     editRef.value?.open('edit')
//     editRef.value?.getDetail(data)
// }

// const handleDelete = async (id: number) => {
//   await feedback.confirm('确定要删除？')
//   await basicDelete({id})
//   feedback.msgSuccess('删除成功')
//   getLists()
// }

getLists()
</script>
